"""

1、泄漏平均值：梯度的走向是由前面梯度决定的
2、条件不佳问题

"""
import numpy as np
import matplotlib.pyplot as plt

w1 = np.linspace(-1, 1, 30)
w2 = np.linspace(-0.8, 0.8, 30)
e = w1 ** 2 + 2 * w2 ** 2

current_w1 = -1
current_w2 = -0.8
lr = 0.4
num_epochs = 10
predict_w = []
for i in range(num_epochs):
    predict_w.append([current_w1, current_w2])
    slope1 = 2 * current_w1
    slope2 = 4 * current_w2
    # SGD 小固定值 * 斜率
    current_w1 -= lr * slope1
    current_w2 -= lr * slope2

predict_w = np.array(predict_w)
x1, x2 = np.meshgrid(w1, w2, indexing='ij')
plt.contour(x1, x2, x1 ** 2 + 2 * x2 ** 2, colors="#1f77b4")
plt.plot(predict_w[:, 0], predict_w[:, 1], 'ro-')
plt.show()
